/*
 * Copyright (c) 2010, Jack Sleight <http://jacksleight.com/>
 * All rights reserved.
 *
 * This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt.
 * It is also available at this URL: http://www.opensource.org/licenses/bsd-license.php
 */

var JS = JS || {};

JS.IE = new Class(
{
	initialize: function()
	{
		if (!Browser.Engine.trident || Browser.Engine.version > 6) {
			return;
		}

		var action = Cookie.read('js_ie') || 'warn';
		if (action == 'skip') {
			return;
		}

		var content = '\
			<h1>Did you know your web browser is out of date?</h1>\
			<p>Upgrading your browser will ensure you have the best possible experience using this web site, and give you many other benefits such as better protection against malicious software and performance enhancements. <a href="http://www.microsoft.com/windows/internet-explorer/get-the-facts/default.aspx" target="_blank">Read more about the benefits of upgrading</a>.</p>\
			<div id="js_ie_choices">\
				<a href="http://www.microsoft.com/Windows/internet-explorer/" target="_blank" id="js_ie_upgrade" class="js_ie_choice">\
					<span class="js_ie_title">Upgrade your browser</span><br>\
					<span class="js_ie_note">Download and install the latest version of Microsoft Internet Explorer</span>\
				</a>\
				<span id="js_ie_continue" class="js_ie_choice">\
					<span class="js_ie_title">Continue with your current browser</span><br>\
					<span class="js_ie_note">Please read the information below.<br>This message will not appear again.</span>\
				</span>\
			</div>\
			<p class="js_ie_note">We have ensured that the most basic features of this site are usable with your browser, however the site will not look as it would in a more recent browser, and some advanced features will be unavaliable.<p>\
			<h2>You may also want to consider an alternative browser:</h2>\
			<p class="js_ie_close">\
				<a href="http://www.mozilla.com/firefox/" target="_blank">Mozilla Firefox</a>,\
				<a href="http://www.google.com/chrome/" target="_blank">Google Chrome</a>,\
				<a href="http://www.apple.com/safari/" target="_blank">Safari</a>,\
				<a href="http://www.opera.com/" target="_blank">Opera</a>\
			</p>\
		';

		var size = $(document.body).getSize();
		var html = $$('html')[0]
			.setStyle('overflow', 'hidden');
		var element = new Element('div', {id: 'js_ie'})
			.setStyles({width: size.x + 'px', height: size.y + 'px'})
			.adopt(new Element('div', {id: 'js_ie_overlay'})
				.setStyles({width: size.x + 'px', height: size.y + 'px'}))
			.adopt(new Element('div', {id: 'js_ie_content'})
				.set('html', content))
			.inject(document.body);

		$$('.js_ie_choice').each(function(element) {
			element.addEvent('mouseover', function(event) {
				element.addClass('hover');
			}.bindWithEvent(this));
			element.addEvent('mouseout', function(event) {
				element.removeClass('hover');
			}.bindWithEvent(this));
		}, this);

		$('js_ie_continue').addEvent('click', function(event) {
			html.setStyle('overflow', 'auto');
			element.destroy();
			Cookie.write('js_ie', 'skip', {duration: 365});
		}.bindWithEvent(this));
	}
});